package info.marlan.view;

import info.marlan.sim.Constants;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.util.Log;
import android.view.View;

public class StatusBar extends View {
	private ShapeDrawable container = new ShapeDrawable(new RectShape());
	private ShapeDrawable percentage = new ShapeDrawable(new RectShape());

	private int percent;
	
	public StatusBar(Context context) {
		super(context);
		setFocusable(true);
		this.container.getPaint().setColor(Color.LTGRAY);
		setMinimumWidth(40);
		setMinimumHeight(120);
	}
	

	@Override
	protected void onDraw(Canvas canvas) {
		int x = 5;
		int y = 5;
		int width = 40;
		int height = 120;
		int offsetHeight = (int)((double)height * ((double)percent / 100.0));
		this.container.setBounds(x, y, x + width, y + height);
		this.container.draw(canvas);
		this.percentage.setBounds(x, y +(height - offsetHeight), x + width, y + height);
		this.percentage.draw(canvas);
		y += height + 5;
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		setMeasuredDimension(getSuggestedMinimumWidth(),
				getSuggestedMinimumHeight());
	}


	public int getPercent() {
		return percent;
	}


	public void setPercent(int percent) {
		if(percent < 60){
			this.percentage.getPaint().setColor(Color.RED);
		}else{
			this.percentage.getPaint().setColor(Color.GREEN);
		}
		this.percent = percent;

	}

}
